// Raf Lempens & Bjorn Schobben
#include "QtRobot.h"
#include "QtRobotMoveAnimation.h"
#include "QtRobotDieAnimation.h"
#include "QtRobotHitAnimation.h"
#include "QtRobotTurnAnimation.h"

QtRobot::QtRobot(const std::string& type, unsigned int initialCellX, unsigned int initialCellY): Robot(type, initialCellX, initialCellY), animationLog(0)
{
	robotSprite = new QtRobotSprite(type);
}

QtRobot::~QtRobot()
{
	if (robotSprite)
	{
		delete robotSprite;
		robotSprite = 0;
	}
}

void QtRobot::SetAnimationLog(QtAnimationLog* log)
{
	animationLog = log;
}


QtRobotSprite* QtRobot::GetSprite() const
{
	return robotSprite;
}

void QtRobot::TurnLeft()
{
	Robot::TurnLeft();

	if (animationLog)
	{
		QtRobotTurnAnimation command;

		command.SetRobot(robotSprite, Direction::WEST);

		animationLog->AddAnimationCommand(&command);
	}
}

void QtRobot::TurnRight()
{
	Robot::TurnRight();

	if (animationLog)
	{
		QtRobotTurnAnimation command;

		command.SetRobot(robotSprite, Direction::EAST);

		animationLog->AddAnimationCommand(&command);
	}
}

void QtRobot::MoveUp()
{
	Robot::MoveUp();

	if (animationLog)
	{
		QtRobotMoveAnimation command;
		
		command.SetRobot(robotSprite, Direction::NORTH);

		animationLog->AddAnimationCommand(&command);
	}
}

void QtRobot::MoveDown()
{
	Robot::MoveDown();

	if (animationLog)
	{
		QtRobotMoveAnimation command;
		
		command.SetRobot(robotSprite, Direction::SOUTH);

		animationLog->AddAnimationCommand(&command);
	}
}

void QtRobot::MoveLeft()
{
	Robot::MoveLeft();

	if (animationLog)
	{
		QtRobotMoveAnimation command;
		
		command.SetRobot(robotSprite, Direction::WEST);

		animationLog->AddAnimationCommand(&command);
	}
}

void QtRobot::MoveRight()
{
	Robot::MoveRight();

	if (animationLog)
	{
		QtRobotMoveAnimation command;
		
		command.SetRobot(robotSprite, Direction::EAST);

		animationLog->AddAnimationCommand(&command);
	}
}

void QtRobot::Hit()
{

	if (animationLog)
	{
		QtRobotHitAnimation command;
		
		command.SetRobot(robotSprite);

		animationLog->AddAnimationCommand(&command);
	}

	Robot::Hit();
}

void QtRobot::Die()
{
	Robot::Die();

	if (animationLog)
	{
		QtRobotDieAnimation command;
		
		command.SetRobot(robotSprite);

		animationLog->AddAnimationCommand(&command);
	}
}
